package org.me.CreateManyImage;

import android.graphics.Canvas;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class TutorialThread extends Thread {
	
	private SurfaceHolder sur;
	private Panel panel;
	boolean running = false;
	
	public TutorialThread(SurfaceHolder _sur, Panel _panel)
	{
		this.sur = _sur;
		this.panel = _panel;
	}
	
	public void setRunning(boolean _run)
	{
		this.running = _run;
	}
	
	public SurfaceHolder getSurfaceHolder()
	{
		return sur;
	}
	
	@Override
	public void run() {
		// TODO Auto-generated method stub
		Canvas canvas;
		while(running)
		{
			canvas = null;
			try
			{
				canvas = sur.lockCanvas(null);
				synchronized(sur){
					panel.onDraw(canvas);
				}
			}
			finally {
				if(canvas!=null)
				// TODO: handle exception
				sur.unlockCanvasAndPost(canvas);
			}
		}
	}

}
